<template>
    <!-- 订单信息 -->
    <div class="mySet">
        <van-nav-bar title="我的设置" left-arrow @click-left="onClickLeft" />
        <div class="content">
            <van-cell clickable title="个人头像" is-link
                @click="routerTo('editInfo', { avatar: user.avatar, nickname: user.nickname })">
                <div style="display: flex;align-items: center;justify-content: flex-end;">
                    <van-image width="40px" height="40px" round fit="contain" :src="user.avatar" />
                </div>
            </van-cell>
            <van-cell clickable title="昵称" is-link
                @click="routerTo('editInfo', { avatar: user.avatar, nickname: user.nickname })">
                {{ user.nickname }}
            </van-cell>
            <van-cell clickable title="手机号绑定" is-link>
                {{ user.mobile }}
            </van-cell>
            <!-- <van-cell clickable title="银行卡管理" is-link>
                {{ user.isBank1 == 1 ? "已绑定" : "去绑定" }}
            </van-cell> -->
            <van-cell clickable title="银行卡管理" is-link @click="routerTo('addbankcard', { type: 1 })">
                {{ user.isBank1 == 1 ? "已绑定" : "去绑定" }}
            </van-cell>
            <van-cell clickable title="微信" is-link
                @click="routerTo('bindInfo', { type: 2, info: user.wechat_info, image: user.wechat_image })">
                {{ !!user.wechat_info ? "已绑定" : "去绑定" }}
            </van-cell>
            <van-cell clickable title="支付宝" is-link
                @click="routerTo('bindInfo', { type: 1, info: user.alipay_info.name, account: user.alipay_info.account })">
                {{ !!user.alipay_info.name && !!user.alipay_info.account ? "已绑定" : "去绑定" }}
            </van-cell>
            <!-- <van-cell clickable title="对公账号" is-link>
                {{ user.isBank1 == 1 ? "已绑定" : "去绑定" }}
            </van-cell> -->
            <van-cell clickable title="对公账号" is-link @click="routerTo('addbank', { type: 1 })">
                {{ user.isBank1 == 1 ? "已绑定" : "去绑定" }}
            </van-cell>
        </div>
        <van-button round block type="primary" @click="exitLogin">
            退出登录
        </van-button>
    </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { Toast } from 'vant';
import { userInfo } from '../../../api/index';
const active = ref(0);
const orderType = ref(3);
const router = useRouter();
const user = ref(JSON.parse(window.localStorage.getItem("userInfo") as string))
let formData = new FormData();
// 定义onClickLeft方法
const onClickLeft = () => history.back();
// const onSubmit = () => Toast('点击按钮');
const routerTo = (str: string, data?: any) => {
    const path = `/mine/myset/${str.toLowerCase()}`;
    if (data) {
        // console.log("发送数据:", data)
        router.push({ path: path, state: data });
    } else {
        router.push(path);
    }
}
const exitLogin = () => {
    Toast("退出成功")
    window.localStorage.removeItem("accessToken");
    router.push({
        path: '/login'
    })
}
onMounted(() => {
    formData = new FormData();
    userInfo(formData).then(res => {
        if (res.code == 1) {
            window.localStorage.setItem("userInfo", JSON.stringify(res.data));
            // store.commit('setUserInfo', res.data)
            user.value = res.data
            // console.log('user.alipay_info.name',user.alipay_info.name);

        } else {
            Toast(res.msg)
            window.localStorage.removeItem("userInfo");
            window.localStorage.removeItem("accessToken");
            router.push({
                path: '/login'
            })
        }
    })
    formData = new FormData();
})
</script>

<style lang="less" scoped>
@import url(../../../style/common.css);

.mySet {
    background: #F9FBFC;
    width: 100%;
    height: 100vh;

    .van-button {
        box-sizing: border-box;
        margin: 0 15px;
        margin-top: 16px;
        width: 345px;
        height: 44px;
        border-radius: 347px 347px 347px 347px;
    }
}

.van-nav-bar {
    width: 100%;
    height: 52px;
}

.content {
    .van-cell {
        padding: 0 20px;
        height: 43px;
        text-align: left;
        display: flex;
        align-items: center;
    }
}


:deep(.van-nav-bar__left .van-badge__wrapper) {
    color: #272635;
}
</style>
